package com.sitech.portal.webHooks.action;

import com.sitech.ibnms.core.IPage;
import com.sitech.ibnms.core.JGridBaseAction;
import com.sitech.ibnms.util.RandomGUID;
import com.sitech.portal.webHooks.domain.WebHooks;
import com.sitech.portal.webHooks.service.IWebHooksService;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;

public class WebHooksAction extends JGridBaseAction{

    private IWebHooksService webHooksService;
    private ArrayList list = new ArrayList();
    private String  id ;

    private WebHooks webHooks = new WebHooks();

    public void setWebHooksService(IWebHooksService webHooksService) {
        this.webHooksService = webHooksService;
    }

    public String webHooksListJson() {
        IPage result = webHooksService.selectWebHooksList(null, this.getPageForm());
        this.setResult(result);
        return SUCCESS;
    }


    public String webHooks() {
        webHooks = webHooksService.selectWebHooksSync(id);
		return SUCCESS;
	}

    public String saveWebHooks() {
        if(StringUtils.isEmpty(webHooks.getID())){
            webHooks.setID(RandomGUID.getRandomGUID());
            webHooksService.addWebHooks(webHooks);
        }else{
            list.add(webHooks.getID());
            webHooksService.delWebHooks(list);
            webHooksService.addWebHooks(webHooks);
        }
        return SUCCESS;
    }
    public String delWebHooks() {
        webHooksService.delWebHooks(list);
        return SUCCESS;
    }

    public ArrayList getList() {
        return list;
    }

    public void setList(ArrayList list) {
        this.list = list;
    }

    public WebHooks getWebHooks() {
        return webHooks;
    }

    public void setWebHooks(WebHooks webHooks) {
        this.webHooks = webHooks;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
